package com.tree.commonresultdemo.result;

/**
 * @author zhong
 * @version 1
 * @date 2022/04/10
 * @contact 1478168700@qq.com
 **/
public final class ResultBuilder<T> {

    private Integer code;
    private String msg;
    private T data;


    private ResultBuilder() {
    }

    public static <T> ResultBuilder aResult() {
        return new ResultBuilder();
    }

    public ResultBuilder withCode(Integer code) {
        this.code = code;
        return this;
    }

    public ResultBuilder withMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public ResultBuilder withData(T data) {
        this.data = data;
        return this;
    }

    public Result build() {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
}
